package com.fjwt.gz.mgr.ctrl.activity;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.ActivityTypeDTO;
import com.fjwt.gz.db.entity.ActivityTypeEntity;
import com.fjwt.gz.db.vo.ActivityTypeVO;
import com.fjwt.gz.mgr.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.ActivityTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 活动类型管理 Controller
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/activity/type")
public class ActivityTypeController extends CommonCtrl {

    @Autowired
    private ActivityTypeService activityTypeService;


    /**
     * 查询活动类型列表
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_ACTIVITY_TYPE_INFO')")
    @GetMapping
    public ApiRes list() {
        ActivityTypeDTO activityTypeDTO = getObject(ActivityTypeDTO.class);
        log.info("pc端查询活动类型列表，请求地址：/api/activity/type，请求参数：{}", JSONUtil.toJsonStr(activityTypeDTO));
        IPage<ActivityTypeVO> page = activityTypeService.queryList(getIPage(true), activityTypeDTO);
        log.info("pc端查询活动类型列表，请求地址：/api/activity/type，返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 新增活动类型
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_ACTIVITY_TYPE_INFO_ADD')")
    @PostMapping
    public ApiRes add() {
        ActivityTypeDTO dto = getObject(ActivityTypeDTO.class);
        log.info("pc端新增活动类型，请求地址：/api/activity/type，请求参数：{}", JSONUtil.toJsonStr(dto));
        activityTypeService.saveActivityType(dto);
        return ApiRes.ok();
    }

    /**
     * 修改活动类型
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_ACTIVITY_TYPE_INFO_EDIT')")
    @PutMapping
    public ApiRes update() {
        ActivityTypeDTO dto = getObject(ActivityTypeDTO.class);
        log.info("pc端修改活动类型，请求地址：/api/activity/type，请求参数：{}", JSONUtil.toJsonStr(dto));
        activityTypeService.updateActivityType(dto);
        return ApiRes.ok();
    }

    /**
     * 删除活动类型
     * @return
     */
    @PreAuthorize("hasAnyAuthority('ENT_ACTIVITY_TYPE_INFO_DEL')")
    @DeleteMapping
    public ApiRes delete() {
        ActivityTypeDTO dto = getObject(ActivityTypeDTO.class);
        activityTypeService.removeActivityType(dto.getActivityTypeNo());
        return ApiRes.ok();
    }


}
